package com.cn.wanxi.servlet.product;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.service.IProductService;
import com.cn.wanxi.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/back/product/findAll")
public class ProductFindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        /**
         * 乱码
         * 拿到前端的值
         * 封装到用户实体类model
         * 调用服务逻辑层
         * 得到结果
         * 返回数据
         */
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");


        IProductService iProductService=new ProductServiceImpl();
        List<ProductModel> list=iProductService.findAll();

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list", list);
        resp.getWriter().println(jsonObject);
    }
    /**
     * 1.图片上传 封装数据
     *      工具类：读写  将formdata保存到req
     * 2.模糊查询   要修改的地方：sql 语句后面的where 条件语句
     * 3.需要拿值
     *    html---css---js  前端
     *    servlet 封装前端得到的数据  findAll（userModel）
     *    service
     *    dao   where修改   字符串拼接
     */
}
